<script setup lang="ts">
import { ref } from 'vue'
import { useUserInfoStore } from '@/stores/index'
import { showShareMenu } from '@/utils/share'
import { onShareAppMessage } from '@dcloudio/uni-app'
import CNav from '@/components/CNav.vue'

const share = ref({})
// 设置分享给朋友的配置
onShareAppMessage(() => {
  return share.value
})

const cacheUserInfo = () => {
  useUserInfoStore().setProfile({
    id: 1,
    avatar: 'http://www.baidu.com',
    username: '张三',
    nickname: 'baidu',
    mobile: 'zhangsan',
    token: 'dfsafsfsaf',
  })
  console.log('存储成功')
}

const clearUserInfo = () => {
  useUserInfoStore().clearProfile()
}
const lClick = () => {
  console.log('lClic11k111')
}

async function showShare() {
  // #ifdef MP-WEIXIN
  share.value = {
    provider: 'weixin',
    scene: 'WXSceneSession',
    type: 0,
    imageUrl:
      'https://i0.hdslb.com/bfs/sycp/creative_img/202410/4d8d7e9ca4ac51e5568d42f06c29bf73.png',
    title: '分享标题1',
    summary: '分享内容',
    href: 'https://jvlihd.cn',
  }
  // #endif

  // #ifdef APP-PLUS
  showShareMenu()
  // #endif
}
</script>
<template>
  <div class="my">
    <CNav title="首页" bgColor="#51d4df" fontColor="#2b9939">
      <template #left>
        <view @tap="lClick">
          <text class="l_text">返回1</text>
          <view class="icon">
            <uv-icon name="photo"></uv-icon>
          </view>
          <!-- <uv-icon name="photo"></uv-icon> -->
          <!-- 图标 -->
        </view>
      </template>
    </CNav>
    <img
      @tap="lClick"
      alt=""
      src="https://i0.hdslb.com/bfs/sycp/creative_img/202410/4d8d7e9ca4ac51e5568d42f06c29bf73.png"
      mode="scaleToFill"
    />
    <uv-icon name="photo"></uv-icon>
    <div>{{ JSON.stringify(useUserInfoStore().profile) }}</div>
    <button @tap="cacheUserInfo()">存储</button>
    <button @tap="clearUserInfo()">清除</button>
    <!-- #ifdef APP-PLUS -->
    <button @tap="showShare()">分享</button>
    <!-- #endif -->
    <!-- #ifdef MP-WEIXIN -->
    <button open-type="share" @tap="showShare()">分享微信好友</button>
    <!-- #endif -->
  </div>
</template>
<style scoped lang="scss">
.l_text {
  display: inline-block;
}
.icon {
  display: inline-block;
}
</style>
